package com.deYang.app.ljodfh.base;

import android.app.Notification;
import android.content.pm.ApplicationInfo;
import android.support.multidex.MultiDexApplication;
import android.util.Log;

import com.iflytek.cloud.SpeechUtility;
import com.jiongbull.jlog.JLog;
import com.mob.MobSDK;
import com.ruihang.generalibrary.utils.DatasVersionManager;
import com.deYang.app.ljodfh.R;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.smtt.sdk.QbSdk;

import org.xutils.x;

import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2017/6/15.
 */

public class SiChuanFocusApplication extends MultiDexApplication {

    private DatasVersionManager datasVersionManager;

    @Override
    public void onCreate() {
        super.onCreate();

        CrashReport.initCrashReport(getApplicationContext(), "d5bfe81597", true);

        MobSDK.init(getApplicationContext(), "27cd0241941fd", "0249b174e8a600321d0156b27426ed33");

        try {
            ApplicationInfo info = getApplicationInfo();
            Constances.isTesting = (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
            if (Constances.isTesting) {
                Debuger.enable();
            } else {
                Debuger.disable();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        JLog.init();
        JLog.getSettings().setDebug(Constances.isTesting);
        x.Ext.init(this);
        x.Ext.setDebug(true);
        JPushInterface.setDebugMode(true);    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);
        Log.e("Sic", JPushInterface.getRegistrationID(this));
        BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(this);
        builder.statusBarDrawable = R.mipmap.ic_launcher;
        builder.notificationFlags = Notification.FLAG_AUTO_CANCEL
                | Notification.FLAG_SHOW_LIGHTS;  //设置为自动消失和呼吸灯闪烁
        builder.notificationDefaults = Notification.DEFAULT_SOUND
                | Notification.DEFAULT_VIBRATE
                | Notification.DEFAULT_LIGHTS;  // 设置为铃声、震动、呼吸灯闪烁都要
        JPushInterface.setPushNotificationBuilder(3, builder);

//搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。

        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {

            @Override
            public void onViewInitFinished(boolean arg0) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
            }
        };
        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);

        SpeechUtility.createUtility(this, "appid=" + getString(R.string.voice_id));
    }

    public synchronized DatasVersionManager getDatasVersionManager() {
        if (datasVersionManager == null) {
            datasVersionManager = DatasVersionManager.getInstance();
        }
        return datasVersionManager;
    }
}
